{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Three Consecutive Odds"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #array"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #数组"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: threeConsecutiveOdds"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #存在连续三个奇数的数组"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给你一个整数数组 <code>arr</code>，请你判断数组中是否存在连续三个元素都是奇数的情况：如果存在，请返回 <code>true</code> ；否则，返回 <code>false</code> 。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>arr = [2,6,4,1]\n",
    "<strong>输出：</strong>false\n",
    "<strong>解释：</strong>不存在连续三个元素都是奇数的情况。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>arr = [1,2,34,3,4,5,7,23,12]\n",
    "<strong>输出：</strong>true\n",
    "<strong>解释：</strong>存在连续三个元素都是奇数的情况，即 [5,7,23] 。\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>1 &lt;= arr.length &lt;= 1000</code></li>\n",
    "\t<li><code>1 &lt;= arr[i] &lt;= 1000</code></li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [three-consecutive-odds](https://leetcode.cn/problems/three-consecutive-odds/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [three-consecutive-odds](https://leetcode.cn/problems/three-consecutive-odds/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['[2,6,4,1]', '[1,2,34,3,4,5,7,23,12]']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def threeConsecutiveOdds(self, arr: List[int]) -> bool:\n",
    "        for i in range(len(arr) - 2):\n",
    "            if arr[i] % 2 and arr[i+1] % 2 and arr[i+2] % 2:\n",
    "                return True \n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def threeConsecutiveOdds(self, arr: List[int]) -> bool:\n",
    "\n",
    "        for i in range(len(arr)-2):\n",
    "\n",
    "            if arr[i] % 2 != 0 and arr[i+1] % 2 != 0 and arr[i+2] % 2 != 0:\n",
    "                return True\n",
    "                \n",
    "            else:\n",
    "                continue\n",
    "        return False\n",
    "        \n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def threeConsecutiveOdds(self, arr: List[int]) -> bool:\n",
    "        for i in range(len(arr)-2):\n",
    "            if arr[i] % 2 !=0 and arr[i+1] % 2 !=0 and arr[i + 2] % 2 !=0:\n",
    "                return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def threeConsecutiveOdds(self, arr: List[int]) -> bool:\n",
    "        for i in range(len(arr) - 2):\n",
    "            if arr[i] % 2== 1 and arr[i+1] % 2== 1 and arr[i+2] % 2== 1:\n",
    "                return True\n",
    "        return False\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def threeConsecutiveOdds(self, arr: List[int]) -> bool:\n",
    "        if len(arr) < 3:\n",
    "            return False\n",
    "        for i in range(len(arr)-2):\n",
    "            if arr[i] % 2 == 1 and arr[i+1] % 2 == 1 and arr[i+2] % 2 == 1:\n",
    "                return True\n",
    "        return False\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def threeConsecutiveOdds(self, arr: List[int]) -> bool:\n",
    "        for i in range(len(arr)-2):\n",
    "            if arr[i] % 2 == 1 and arr[i+1]%2 == 1 and arr[i+2]%2 == 1:\n",
    "                return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def threeConsecutiveOdds(self, arr: List[int]) -> bool:\n",
    "        c = 0\n",
    "        for n in arr:\n",
    "            if n & 1:\n",
    "                c += 1\n",
    "                if c == 3:\n",
    "                    return True\n",
    "            else:\n",
    "                c = 0\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def threeConsecutiveOdds(self, arr: List[int]) -> bool:\n",
    "        flag = False\n",
    "        count = 0\n",
    "        for i in arr:\n",
    "            if i % 2:\n",
    "                flag = True\n",
    "                count += 1\n",
    "                if count == 3:\n",
    "                    return True\n",
    "            elif flag:\n",
    "                flag = False\n",
    "                count = 0\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def threeConsecutiveOdds(self, arr: List[int]) -> bool:\n",
    "        stack = []\n",
    "        for c in arr:\n",
    "            if c % 2 != 0:\n",
    "                stack.append(c)\n",
    "                if len(stack) >= 3:\n",
    "                    return True\n",
    "            else:\n",
    "                stack.clear()\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def threeConsecutiveOdds(self, arr: List[int]) -> bool:\n",
    "        res = 0\n",
    "        for n in arr:\n",
    "            res = res + 1 if n & 1 else 0\n",
    "            if res >= 3: return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def threeConsecutiveOdds(self, arr: List[int]) -> bool:\n",
    "        for i in range(len(arr)-2):\n",
    "            if(arr[i]%2!=0 and arr[i+1]%2!=0 and arr[i+2]%2!=0):\n",
    "                return True\n",
    "            else:\n",
    "                continue\n",
    "        return  False\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def threeConsecutiveOdds(self, arr: List[int]) -> bool:\n",
    "        for i in range(len(arr) - 2):\n",
    "            if arr[i] % 2 and arr[i + 1] % 2 and arr[i + 2] % 2:\n",
    "                return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def threeConsecutiveOdds(self, arr: List[int]) -> bool:\n",
    "        tmpset = []\n",
    "        for item in arr:\n",
    "            if item % 2 != 0:\n",
    "                tmpset.append(item)\n",
    "                if len(tmpset) == 3:\n",
    "                    return True\n",
    "            else:\n",
    "                tmpset.clear()\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def threeConsecutiveOdds(self, arr: List[int]) -> bool:\n",
    "        n = len(arr)\n",
    "        if n < 3:\n",
    "            return False\n",
    "        wind_lst = [arr[0],arr[1],arr[2]]\n",
    "        for j in wind_lst:\n",
    "            if j % 2 == 0:\n",
    "                break\n",
    "        else:\n",
    "            return True\n",
    "        for i in range(3,n):\n",
    "            wind_lst.pop(0)\n",
    "            wind_lst.append(arr[i])\n",
    "            for j in wind_lst:\n",
    "                if j % 2 == 0:\n",
    "                    break\n",
    "            else:\n",
    "                return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def threeConsecutiveOdds(self, arr: List[int]) -> bool:\n",
    "        for i in range(len(arr)-2):\n",
    "            if arr[i] % 2 == 1 and arr[i+1] % 2 == 1 and arr[i+2] % 2 == 1:\n",
    "                return True\n",
    "        return False\n",
    "\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def threeConsecutiveOdds(self, arr: List[int]) -> bool:\n",
    "        stack=[]\n",
    "        for a in arr:\n",
    "            if a%2!=0 and len(stack)<3:\n",
    "                stack.append(a)\n",
    "            elif len(stack)==3:\n",
    "                return True\n",
    "            else:\n",
    "                stack=[]\n",
    "        if len(stack)==3:\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def threeConsecutiveOdds(self, arr: List[int]) -> bool:\n",
    "        for i in range(1,len(arr)-1):\n",
    "            if arr[i]%2 and arr[i-1]%2 and arr[i+1]%2:\n",
    "                return True\n",
    "        return False\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def threeConsecutiveOdds(self, arr: List[int]) -> bool:\n",
    "\n",
    "        if len(arr) < 3:\n",
    "            return False\n",
    "\n",
    "        for i in range(len(arr) - 2):\n",
    "            if arr[i] % 2 == 1 and arr[i+1] % 2 == 1 and arr[i+2]%2 == 1:\n",
    "                return True\n",
    "            else:\n",
    "                continue\n",
    "        return False\n",
    "\n",
    "\n",
    "        \n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def threeConsecutiveOdds(self, arr: List[int]) -> bool:\n",
    "        n = len(arr)\n",
    "        for i in range(n-2):\n",
    "            if arr[i] % 2 == 1 and arr[i+1] % 2 == 1 and arr[i+2] % 2 == 1:\n",
    "                return True\n",
    "\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def threeConsecutiveOdds(self, arr: List[int]) -> bool:\n",
    "        n = len(arr)\n",
    "        return n >= 3 and \\\n",
    "            any(arr[i] & 1 and arr[i + 1] & 1 and arr[i + 2] & 1 \\\n",
    "                for i in range(n - 2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def threeConsecutiveOdds(self, arr: List[int]) -> bool:\n",
    "        for i in range(len(arr)-2):\n",
    "            if (arr[i]%2!=0 and arr[i+1]%2 !=0 and arr[i+2] % 2!=0):\n",
    "                return True\n",
    "            else:\n",
    "                continue\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def threeConsecutiveOdds(self, arr: List[int]) -> bool:\n",
    "        for i in range(len(arr)-2):\n",
    "            if(arr[i]%2!=0 and arr[i+1]%2!=0 and arr[i+2]%2!=0):\n",
    "                return True\n",
    "            else:\n",
    "                continue\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def threeConsecutiveOdds(self, arr: List[int]) -> bool:\n",
    "        n = len(arr)\n",
    "        for i in range(n-2):\n",
    "            if arr[i] % 2 == 1 and arr[i+1] % 2 == 1 and arr[i+2] % 2 == 1:\n",
    "                return True\n",
    "\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def threeConsecutiveOdds(self, arr: List[int]) -> bool:\n",
    "        length = len(arr)\n",
    "        for index in range(length - 2):\n",
    "            num1 = arr[index]\n",
    "            num2 = arr[index+1]\n",
    "            num3 = arr[index+2]\n",
    "            if (num1 % 2==1 and num2 % 2 == 1 and num3 % 2 == 1):\n",
    "                return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def threeConsecutiveOdds(self, arr: List[int]) -> bool:\n",
    "        s = 0\n",
    "        for i in arr:\n",
    "            if i % 2 == 0:\n",
    "                s = 0\n",
    "            else:\n",
    "                s += 1\n",
    "                if s == 3:\n",
    "                    return True \n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def threeConsecutiveOdds(self, arr: List[int]) -> bool:\n",
    "        counter = 0\n",
    "        for i in arr:\n",
    "            if i % 2 != 0:\n",
    "                counter += 1\n",
    "            else:\n",
    "                counter = 0\n",
    "            if counter == 3:\n",
    "                return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def threeConsecutiveOdds(self, arr: List[int]) -> bool:\n",
    "        for i in range(len(arr)-2):\n",
    "            if(arr[i]%2!=0 and arr[i+1]%2!=0 and arr[i+2]%2!=0):\n",
    "                return True\n",
    "            else:\n",
    "                continue\n",
    "        return  False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def threeConsecutiveOdds(self, arr: List[int]) -> bool:\n",
    "        return any(all(arr[i + j] % 2 for j in range(3)) for i in range(len(arr) - 2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def threeConsecutiveOdds(self, arr: List[int]) -> bool:\n",
    "        count = 0\n",
    "        for num in arr:\n",
    "            if num % 2 == 1:\n",
    "                count += 1\n",
    "            else: count = 0\n",
    "            if count == 3: return True\n",
    "            \n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def threeConsecutiveOdds(self, arr: List[int]) -> bool:\n",
    "        c=0\n",
    "        for n in arr:\n",
    "            if n%2==0:\n",
    "                c=0\n",
    "            else:\n",
    "                c+=1\n",
    "                if c>=3:\n",
    "                    return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def threeConsecutiveOdds(self, arr: List[int]) -> bool:\n",
    "        res = [\"T\" if a%2==1 else \"F\" for a in arr]\n",
    "        return \"TTT\" in \"\".join(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def threeConsecutiveOdds(self, arr: List[int]) -> bool:\n",
    "        x = 0\n",
    "        return any((x := (x+1) * (v&1)) == 3 for v in arr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def threeConsecutiveOdds(self, arr: List[int]) -> bool:\n",
    "        for i in range(2,len(arr)):\n",
    "            if arr[i]%2==1 and arr[i-1]%2==1 and arr[i-2]%2==1:\n",
    "                return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def threeConsecutiveOdds(self, arr: List[int]) -> bool:\n",
    "        for i in range(len(arr)-2):\n",
    "            if arr[i]%2 == 1:\n",
    "                if arr[i+1]%2==1 and arr[i+2]%2==1:\n",
    "                    return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def threeConsecutiveOdds(self, arr: List[int]) -> bool:\n",
    "        num = 0\n",
    "        for i in arr:\n",
    "            if i & 1:\n",
    "                num += 1\n",
    "                if num > 2:\n",
    "                    return True\n",
    "            else:\n",
    "                num = 0\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def threeConsecutiveOdds(self, arr: List[int]) -> bool:\n",
    "        odd = 0\n",
    "        for x in arr:\n",
    "            if x % 2:\n",
    "                odd += 1\n",
    "                if odd >= 3:\n",
    "                    return True\n",
    "            else:\n",
    "                odd = 0\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def threeConsecutiveOdds(self, arr: List[int]) -> bool:\n",
    "        for i in range(len(arr)-2):\n",
    "            if(arr[i]%2!=0 and arr[i+1]%2!=0 and arr[i+2]%2!=0):\n",
    "                return True\n",
    "        return False\n",
    "            \n",
    "        \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def threeConsecutiveOdds(self, arr: List[int]) -> bool:\n",
    "        num = 0\n",
    "        for i in arr:\n",
    "            if i & 1:\n",
    "                num += 1\n",
    "                if num > 2:\n",
    "                    return True\n",
    "            else:\n",
    "                num = 0\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def threeConsecutiveOdds(self, arr: List[int]) -> bool:\n",
    "        n = len(arr)\n",
    "        for i in range(2,n):\n",
    "            if(arr[i] % 2 == 1 and arr[i-1] % 2 == 1 and arr[i-2] % 2 == 1):\n",
    "                return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def threeConsecutiveOdds(self, arr: List[int]) -> bool:\n",
    "        len_arr = len(arr) \n",
    "        i = 0\n",
    "        \n",
    "        while i < len_arr:\n",
    "            num = 0\n",
    "            j = i\n",
    "            while j < len_arr and arr[j]%2==1:\n",
    "                num+=1\n",
    "                j+=1\n",
    "                if num>=3:\n",
    "                    return True\n",
    "            i=j+1\n",
    "        return False\n",
    "        \n",
    "                \n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def threeConsecutiveOdds(self, arr: List[int]) -> bool:\n",
    "        for i in range(2,len(arr)):\n",
    "            if arr[i-2]%2 ==1 and arr[i-1]%2 == 1 and arr[i]%2 == 1:\n",
    "                return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def threeConsecutiveOdds(self, arr: List[int]) -> bool:\n",
    "        res = 0\n",
    "        for i in arr:\n",
    "            if i%2!=0:\n",
    "                res+=1\n",
    "            else:\n",
    "                res = 0\n",
    "            if res==3:\n",
    "                return True\n",
    "        \n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def threeConsecutiveOdds(self, arr: List[int]) -> bool:\n",
    "        cnt = 0\n",
    "        for num in arr:\n",
    "            if num % 2 == 1:\n",
    "                cnt += 1\n",
    "            else:\n",
    "                cnt = 0\n",
    "            if cnt == 3:\n",
    "                return True\n",
    "        \n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def threeConsecutiveOdds(self, arr: List[int]) -> bool:\n",
    "        for i in range(len(arr)-2):\n",
    "            if arr[i]%2 ==1 and arr[i+1]%2 ==1 and arr[i+2]%2 ==1 :\n",
    "                return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def threeConsecutiveOdds(self, arr: List[int]) -> bool:\n",
    "        l=0\n",
    "        r=0\n",
    "        n=len(arr)\n",
    "        while r<n:\n",
    "            if arr[r]%2==1:\n",
    "                r+=1\n",
    "            else:\n",
    "                l=r+1\n",
    "                r=l\n",
    "            if r-l==3:\n",
    "                return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def threeConsecutiveOdds(self, arr: List[int]) -> bool:\n",
    "        for i in range(len(arr)-2):\n",
    "            if arr[i]%2==arr[i+1]%2==arr[i+2]%2==1:\n",
    "                return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def threeConsecutiveOdds(self, arr: List[int]) -> bool:\n",
    "        flag = 0\n",
    "        for i in arr:\n",
    "            if flag == 3:\n",
    "                return True\n",
    "            if i % 2 == 1:\n",
    "                flag += 1\n",
    "            else:\n",
    "                flag = 0\n",
    "        if flag == 3:\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def threeConsecutiveOdds(self, arr: List[int]) -> bool:\n",
    "        for i in range(len(arr)-2):\n",
    "            if arr[i]%2!=0 and arr[i+1]%2!=0 and arr[i+2]%2!=0:\n",
    "                return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def threeConsecutiveOdds(self, arr: List[int]) -> bool:\n",
    "        n = len(arr)\n",
    "        if n <= 2:\n",
    "            return False\n",
    "        arr[0], arr[1] = arr[0] % 2, arr[1] % 2\n",
    "        for i in range(2, n):\n",
    "            arr[i] = arr[i] % 2\n",
    "            if arr[i] == arr[i-1] == arr[i-2] == 1:\n",
    "                return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def threeConsecutiveOdds(self, arr: List[int]) -> bool:\n",
    "        if len(arr)<3:\n",
    "            return False\n",
    "        for i in range(0,len(arr)-2):\n",
    "            if arr[i]%2==1 and arr[i+1]%2==1 and arr[i+2]%2==1:\n",
    "                return True\n",
    "                break\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def threeConsecutiveOdds(self, arr: List[int]) -> bool:\n",
    "        for i in range(2,len(arr)):\n",
    "            if arr[i-2]%2 ==1 and arr[i-1]%2 == 1 and arr[i]%2 == 1:\n",
    "                return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def threeConsecutiveOdds(self, arr: List[int]) -> bool:\n",
    "        n = len(arr)\n",
    "        i = 0\n",
    "        while n - i >= 3:\n",
    "            if arr[i + 2] % 2 == 0:\n",
    "                i += 3\n",
    "            elif arr[i + 1] % 2 == 0:\n",
    "                i += 2\n",
    "            elif arr[i] % 2 == 0:\n",
    "                i += 1\n",
    "            else:\n",
    "                return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def threeConsecutiveOdds(self, arr: List[int]) -> bool:\n",
    "        for i in range(len(arr)-2):\n",
    "            if arr[i]%2!=0 and arr[i+1]%2!=0 and arr[i+2]%2!=0:\n",
    "                return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def threeConsecutiveOdds(self, arr: List[int]) -> bool:\n",
    "        cnt = 0\n",
    "        for num in arr:\n",
    "            if num % 2 == 1:\n",
    "                cnt += 1\n",
    "            else:\n",
    "                cnt = 0\n",
    "            if cnt == 3:\n",
    "                return True\n",
    "        \n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def threeConsecutiveOdds(self, arr: List[int]) -> bool:\n",
    "        rs=[i%2 for i in arr]\n",
    "        ts=0\n",
    "        for i in range(len(arr)):\n",
    "            if rs[i]==1:\n",
    "                ts+=1\n",
    "                if ts==3:\n",
    "                    return True\n",
    "            else:\n",
    "                ts=0\n",
    "        return False\n",
    "            \n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def threeConsecutiveOdds(self, arr: List[int]) -> bool:\n",
    "        for i in range(len(arr) - 2):\n",
    "            if arr[i] % 2 and arr[i + 1] % 2 and arr[i + 2] % 2:\n",
    "                return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def threeConsecutiveOdds(self, arr: List[int]) -> bool:\n",
    "        num = 0\n",
    "        for i in arr:\n",
    "            if i & 1:\n",
    "                num += 1\n",
    "                if num > 2:\n",
    "                    return True\n",
    "            else:\n",
    "                num = 0\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def threeConsecutiveOdds(self, arr: List[int]) -> bool:\n",
    "        num = 0\n",
    "        for i in arr:\n",
    "            if i & 1:\n",
    "                num += 1\n",
    "                if num > 2:\n",
    "                    return True\n",
    "            else:\n",
    "                num = 0\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def threeConsecutiveOdds(self, arr: List[int]) -> bool:\n",
    "        for i in range(len(arr)-2):\n",
    "            if(arr[i]%2!=0 and arr[i+1]%2!=0 and arr[i+2]%2!=0):\n",
    "                return True\n",
    "            else:\n",
    "                continue\n",
    "        return  False\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def threeConsecutiveOdds(self, arr: List[int]) -> bool:\n",
    "        n = len(arr)\n",
    "        for i in range(n - 2):\n",
    "            if arr[i] % 2 and arr[i + 1] % 2 and arr[i + 2] % 2:\n",
    "                return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def threeConsecutiveOdds(self, arr: List[int]) -> bool:\n",
    "        n=len(arr)\n",
    "        if n<3:return False\n",
    "        for i in range(n-2):\n",
    "            if arr[i]%2:\n",
    "                if i+2<n and arr[i+1]%2 and arr[i+2]%2:\n",
    "                    return True \n",
    "        return False\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def threeConsecutiveOdds(self, arr: List[int]) -> bool:\n",
    "        for i in range(2, len(arr)):\n",
    "            if arr[i]&1 and arr[i-1]&1 and arr[i-2]&1:\n",
    "                return True \n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def threeConsecutiveOdds(self, arr: List[int]) -> bool:\n",
    "        n=len(arr)\n",
    "        for i in range(n-2):\n",
    "            if arr[i]%2==1 and arr[i+1]%2==1 and arr[i+2]%2==1:\n",
    "                return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def threeConsecutiveOdds(self, arr: List[int]) -> bool:\n",
    "        ans = []\n",
    "        for i in arr:\n",
    "            ans.append(str(i%2))\n",
    "        return '111' in ''.join(ans)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def threeConsecutiveOdds(self, arr: List[int]) -> bool:\n",
    "        cou = 0\n",
    "        for a in arr:\n",
    "            if a%2 != 0: \n",
    "                cou +=1\n",
    "                if cou == 3: return True\n",
    "            else: cou = 0\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def threeConsecutiveOdds(self, arr: List[int]) -> bool:\n",
    "        for i in range(1,len(arr)-1):\n",
    "            if arr[i-1]%2!=0 and arr[i]%2!=0 and arr[i+1]%2!=0:\n",
    "                return True\n",
    "        return False"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
